/**
 @file        ScatterWeb.Mutex.h
 @ingroup     system						
 @brief       simple mutex for only two(!) concurrent locks
 @version     $0.1$					
 @since       1.0
 @author      Andreas Schlueter

 

 $Id$
 */


#ifndef SCATTERWEB_MUTEX
#define SCATTERWEB_MUTEX

#include <ScatterWeb.System.h>

///number of system mutexes
#define MUTEX_NUM 3

/**
 * @brief all supported DEVICES
 */
//#define	MUTEX_DMA   0
//#define	MUTEX_USART 1
enum mutex_dev{
	MUTEX_DMA=0,
	MUTEX_USART=1,
	MUTEX_CPU=2 
};


/**
 * @brief callback function of consumer, called when lock is possible
 */
typedef void(*fp_consumer)(enum mutex_dev device);

/**
 * @brief	initializes mutex
 * @param m enumeration mutex
 */
void mutex_init(enum mutex_dev m);

/**
 * @brief	locks mutex
 * @param m enumeration mutex
 * @param c consumer called when lock is possible
 */
void mutex_lock(enum mutex_dev m, fp_consumer c);

/**
 * @brief	unlocks mutex and calls a waiting consumer
 * @param m enumeration mutex
 */
void mutex_unlock(enum mutex_dev m);


/**
 * @brief	checks mutex status
 * @param m enumeration mutex
 * @return true, if mutex is locked
 */
bool mutex_locked(enum mutex_dev m);
#endif

